package cn.iocoder.yudao.module.biz.service.customer.serviceUnit.team;

import cn.iocoder.yudao.module.biz.controller.admin.customer.serviceUnit.team.vo.ServiceUnitTeamPageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.customer.serviceUnit.team.vo.ServiceUnitTeamSaveReqVO;
import cn.iocoder.yudao.module.biz.dal.dataobject.customer.serviceUnit.team.ServiceUnitTeamDO;
import cn.iocoder.yudao.module.biz.dal.mysql.customer.serviceUnit.team.ServiceUnitTeamMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;



import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 客户管理-服务单元-内部小组 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ServiceUnitTeamServiceImpl implements ServiceUnitTeamService {

    @Resource
    private ServiceUnitTeamMapper serviceUnitTeamMapper;

    @Override
    public Long createServiceUnitTeam(ServiceUnitTeamSaveReqVO createReqVO) {
        // 插入
        ServiceUnitTeamDO serviceUnitTeam = BeanUtils.toBean(createReqVO, ServiceUnitTeamDO.class);
        serviceUnitTeamMapper.insert(serviceUnitTeam);

        // 返回
        return serviceUnitTeam.getId();
    }

    @Override
    public void updateServiceUnitTeam(ServiceUnitTeamSaveReqVO updateReqVO) {
        // 校验存在
        validateServiceUnitTeamExists(updateReqVO.getId());
        // 更新
        ServiceUnitTeamDO updateObj = BeanUtils.toBean(updateReqVO, ServiceUnitTeamDO.class);
        serviceUnitTeamMapper.updateById(updateObj);
    }

    @Override
    public void deleteServiceUnitTeam(Long id) {
        // 校验存在
        validateServiceUnitTeamExists(id);
        // 删除
        serviceUnitTeamMapper.deleteById(id);
    }

    @Override
        public void deleteServiceUnitTeamListByIds(List<Long> ids) {
        // 删除
        serviceUnitTeamMapper.deleteByIds(ids);
        }


    private void validateServiceUnitTeamExists(Long id) {
        if (serviceUnitTeamMapper.selectById(id) == null) {
            throw exception(BIZ_CUSTOMER_ARCHIVE_SERVICE_UNIT_TEAM_NOT_EXISTS);
        }
    }

    @Override
    public ServiceUnitTeamDO getServiceUnitTeam(Long id) {
        return serviceUnitTeamMapper.selectById(id);
    }

    @Override
    public PageResult<ServiceUnitTeamDO> getServiceUnitTeamPage(ServiceUnitTeamPageReqVO pageReqVO) {
        return serviceUnitTeamMapper.selectPage(pageReqVO);
    }

}